package com.huiquan.section.service;

import com.huiquan.analysis.domain.User;
import com.huiquan.foundation.constant.BusinessContants;
import com.huiquan.framework.base.BaseService;
import com.huiquan.framework.base.ReturnCode;
import com.huiquan.framework.base.ReturnData;
import com.huiquan.framework.dao.StaticDataDao;
import com.huiquan.framework.domain.StaticData;
import com.huiquan.framework.utils.GetListUtil;
import com.huiquan.framework.utils.ReturnUtil;
import com.huiquan.section.dao.*;
import com.huiquan.section.domain.Section;
import com.huiquan.section.domain.SectionCode;
import com.huiquan.section.domain.SectionImage;
import org.apache.commons.lang.StringUtils;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.io.*;
import java.util.*;

@Service
public class SectionImageService extends BaseService {

    @Autowired
    private SectionImageDao sectionImageDao;
    @Autowired
    private SectionDao sectionDao;
    @Autowired
    private StaticDataDao staticDataDao;
    @Autowired
    private SectionCodeDao sectionCodeDao;
    @Autowired
    private SectionBlackDao sectionBlackDao;
    @Autowired
    private SectionHospitalDao sectionHospitalDao;
    /**
     * 科室模块图片映射的虚拟路径
     */
    public static final String FICTITIOUS_IMAGE_PATH = "/sections/";

    /**
     * 获取检验大类列表
     *
     * @return
     */
    public ModelAndView list(String startStr, String nameKey, String exactSearchFlag, String countPerPageStr, String className) {

        Map<String, Object> param = new HashMap<>();
        if (nameKey != null && !nameKey.isEmpty()) {
            if (exactSearchFlag != null && exactSearchFlag.equals("1")) {
                param.put("keyword", nameKey);
            } else {
                param.put("keyword", "%" + nameKey + "%");
            }
        }
        if (className != null && !className.isEmpty()) {
            if (exactSearchFlag != null && exactSearchFlag.equals("1")) {
                param.put("className", className);
            } else {
                param.put("className", "%" + className + "%");
            }
        }
        int totalSize = sectionImageDao.retrieveSize(param);

        Map<String, Integer> pageNo;
        if (countPerPageStr != null && !countPerPageStr.isEmpty()) {
            int countPerPage = Integer.parseInt(countPerPageStr);
            pageNo = GetListUtil.getPageNoParam(totalSize, startStr, countPerPage);
            param.put("countPerPage", countPerPage);
        } else {
            pageNo = GetListUtil.getPageNoParam(totalSize, startStr);
        }
        int endPage = pageNo.get("endPage");
        int start = pageNo.get("start");
        int startIndex = pageNo.get("startIndex");

        List<SectionImage> list = new ArrayList<>();

        if (startIndex < totalSize) {
            param.put("startIndex", startIndex);
            list = sectionImageDao.retrieveList(param);
        }

        Map<String, String> showSearch = new LinkedHashMap<>();
        showSearch.put("nameKey", "科室名称");
        showSearch.put("className", "科室大类");

        Map<String, Object> map = GetListUtil.getReturnMap2(totalSize, start, startIndex, endPage, list, null);
        map.put("showSearch", showSearch);
        map.put("ageArray", BusinessContants.ageArray);
        //查询是否含有新增了同义词但没有新增其他的科室图片之类的
        List<StaticData> sds = staticDataDao.retrieveByCode("SECTION_ADD_WARN");
        List<StaticData> warnList = new ArrayList<>();
        if (sds != null && sds.size() > 0) {
            for (StaticData sd : sds) {
                warnList.add(sd);
            }
        }
        if (warnList.size() > 0) {
            map.put("warn", "1");
            map.put("warnList", warnList);
        }
        return new ModelAndView("section/index", map);
    }

    /**
     * 上传图片保存路径
     */
    @Value("${section.image.path}")
    private String uploadImagePath;

    /**
     * 插入一个科室图片
     *
     * @param user
     * @param image
     * @return
     * @throws IllegalStateException
     * @throws IOException
     */
    public ReturnData insert(String name, String rank, String nameClass, User user, MultipartFile image)
            throws IllegalStateException, IOException {
        if (image != null) {
            String imageName = image.getOriginalFilename();
            int count = sectionImageDao.retrieveSizeByName(imageName, null);
            if (count > 0) {
                ReturnCode rc = ReturnCode.DYNAMIC_DESC_EXCEPTION;
                rc.setDesc("该图片名称已经存在" + image.getOriginalFilename());
                return ReturnUtil.fail(rc);
            }
            //校验改科室大类的rank是否已经存在
            List<SectionImage> list = sectionImageDao.retrieveByClassAndRank(nameClass, rank);
            if (list != null && list.size() > 0) {
                ReturnCode rc = ReturnCode.DYNAMIC_DESC_EXCEPTION;
                rc.setDesc("该排序在该科室大类下已经存在");
                return ReturnUtil.fail(rc);
            }
            // 插入到mysql
            createClass(name, rank, nameClass, imageName, FICTITIOUS_IMAGE_PATH + imageName, user);
            //删除已经没有对应的section。已经失效
            sectionDao.deleteSectionInvalid();

            //校验科室图片或科室大类是否都在同义词的标准词中
            //校验国家对应科室是否在科室图片名称中
            checkData(true);
            // 上传文件并获得文件URL
            uploadImage(image, imageName);
            return ReturnUtil.success();

        } else {
            ReturnCode rc = ReturnCode.DYNAMIC_DESC_EXCEPTION;
            rc.setDesc("文件上传失败");
            return ReturnUtil.fail(rc);
        }
    }

    /**
     * 更新一个大类的图片
     *
     * @param id
     * @param user
     * @param image
     * @return
     * @throws IllegalStateException
     * @throws IOException
     */
    public ReturnData updateImage(String id, User user, MultipartFile image) throws IllegalStateException, IOException {
        SectionImage tc = sectionImageDao.retrieveObjectById(Long.parseLong(id));
        String imageName = image.getOriginalFilename();
        String path = "";
        if (StringUtils.isNotBlank(imageName)) {
            path = uploadImagePath + imageName;
        }
        File file = new File(path);
        // 如果新图片名和原图片名不同，要更新图片名和URL
        //替换文件
        image.transferTo(file);
        tc.setImageName(imageName);
        tc.setImageUrl(FICTITIOUS_IMAGE_PATH + imageName);
        tc.setModifierId(user.getUserId() + "");
        sectionImageDao.update(tc);

        return ReturnUtil.success();
    }


    /**
     * 上传图片到服务器
     *
     * @param image     图片文件流
     * @param imageName 图片名
     * @return
     * @throws IOException
     * @throws IllegalStateException
     */
    private String uploadImage(MultipartFile image, String imageName) throws IllegalStateException, IOException {
        String path = uploadImagePath + imageName;
        File file = new File(path);
        image.transferTo(file);
        return FICTITIOUS_IMAGE_PATH + imageName;
    }

    /**
     * 创建一个SectionImage并插入到MySql
     *
     * @param imageName
     * @param imageURL
     * @param user
     * @return
     */
    public Long createClass(String name, String rank, String nameClass, String imageName, String imageURL, User user) {

        SectionImage si = new SectionImage();
        Map<String, Object> param = new HashMap<>();
        if (StringUtils.isNotBlank(name)) {
            param.put("name", name);
            List<Section> s = sectionDao.retrieveList(param);
            if (s.size() == 1) {
                si.setSectionId(s.get(0).getId() + "");
            } else if (s.size() == 0) {
                //不存在需要新增
                Section value = new Section();
                value.setCnt(1);
                value.setDisable("0");
                value.setModifierId(user.getUserId());
                value.setName(name);
                value.setSexAgeFlag(0);
                value.setSex(0);
                value.setAge("");
                Long id = sectionDao.insert(value);
                si.setSectionId(id + "");
            }
        } else {
            si.setSectionId("0");
        }
        si.setRank(Integer.parseInt(rank));
        if (StringUtils.isNotBlank(nameClass)) {
            param.clear();
            param.put("name", nameClass);
            List<Section> s2 = sectionDao.retrieveList(param);
            if (s2.size() == 1) {
                si.setSectionClassId(s2.get(0).getId() + "");
            } else if (s2.size() == 0) {
                //不存在需要新增
                Section value = new Section();
                value.setCnt(1);
                value.setDisable("0");
                value.setModifierId(user.getUserId());
                value.setName(nameClass);
                value.setSexAgeFlag(0);
                value.setSex(0);
                value.setAge("");
                Long id = sectionDao.insert(value);
                si.setSectionClassId(id + "");
            }
        } else {
            si.setSectionClassId("0");
        }
        si.setImageName(imageName);
        si.setImageUrl(imageURL);
        si.setModifierId(user.getUserId() + "");
        return sectionImageDao.insert(si);
    }


    /**
     * 删除一个记录
     *
     * @param id
     */
    public ReturnData deleteClass(String id) {
        SectionImage tc = new SectionImage();
        tc.setId(Long.valueOf(id));
        sectionImageDao.delete(tc);
        //校验 删除时需要校验科室大类
        checkData(true);
        return ReturnUtil.success();
    }


    public ReturnData update(String id, String name, String departmentClass, String imageName, String rank, User user) throws RuntimeException {
        SectionImage si = new SectionImage();
        //修改数据
        if (StringUtils.isNotEmpty(name)) {
            si = sectionImageDao.retrieveObjectByIdSection(Long.parseLong(id));
            Map<String, Object> param = new HashMap<>();
            param.put("name", name);
            List<Section> s = sectionDao.retrieveList(param);
            param.clear();
            param.put("name", si.getSectionClassId());
            List<Section> s2 = sectionDao.retrieveList(param);
            if (s.size() == 1) {
                si.setSectionId(s.get(0).getId() + "");
                si.setSectionClassId(s2.get(0).getId() + "");
            } else if (s.size() == 0) {
                //不存在需要新增
                Section value = new Section();
                value.setCnt(1);
                value.setDisable("0");
                value.setModifierId(user.getUserId());
                value.setName(name);
                value.setSexAgeFlag(0);
                value.setSex(0);
                value.setAge("");
                Long sectionId = sectionDao.insert(value);
                si.setSectionId(sectionId + "");
                si.setSectionClassId(s2.get(0).getId() + "");
            }
        } else if (StringUtils.isNotEmpty(imageName)) {
            si = sectionImageDao.retrieveObjectById(Long.parseLong(id));
            //修改图片名字
            renameFile(uploadImagePath, si.getImageName(), imageName);
            //保存记录
            String imageURL = si.getImageUrl();
            imageURL = imageURL.replace(si.getImageName(), imageName);
            si.setImageName(imageName);
            si.setImageUrl(imageURL);
            si.setModifierId(user.getUserId() + "");
            sectionImageDao.update(si);
        } else if (StringUtils.isNotEmpty(rank)) {
            si = sectionImageDao.retrieveObjectById(Long.parseLong(id));
            //校验改科室大类的rank是否已经存在
            List<SectionImage> list = sectionImageDao.retrieveByClassAndRank(si.getSectionClassId(), rank);
            if (list != null && list.size() > 0) {
                ReturnCode rc = ReturnCode.DYNAMIC_DESC_EXCEPTION;
                rc.setDesc("该排序在该科室大类下已经存在");
                return ReturnUtil.fail(rc);
            }
            si.setRank(Integer.parseInt(rank));
        } else {
            si = sectionImageDao.retrieveObjectByIdSection(Long.parseLong(id));
            Map<String, Object> param = new HashMap<>();
            param.put("name", departmentClass);
            List<Section> s = sectionDao.retrieveList(param);
            param.clear();
            param.put("name", si.getSectionId());
            List<Section> s2 = sectionDao.retrieveList(param);
            if (s.size() == 1) {
                si.setSectionClassId(s.get(0).getId() + "");
                si.setSectionId(s2.get(0).getId() + "");
            } else if (s.size() == 0) {
                //不存在需要新增
                Section value = new Section();
                value.setCnt(1);
                value.setDisable("0");
                value.setModifierId(user.getUserId());
                value.setName(departmentClass);
                value.setSexAgeFlag(0);
                value.setSex(0);
                value.setAge("");
                Long sectionId = sectionDao.insert(value);
                si.setSectionClassId(sectionId + "");
                si.setSectionId(s2.get(0).getId() + "");
            }
        }
        si.setModifierId(user.getUserId() + "");
        if (StringUtils.isEmpty(imageName)) {
            sectionImageDao.update(si);
        }
        if (StringUtils.isNotBlank(departmentClass)) {
            checkData(true);
        } else {
            checkData(false);
        }
        //删除已经没有对应的section。已经失效
        sectionDao.deleteSectionInvalid();
        return ReturnUtil.success();


    }

    private void checkData(boolean checkNameClassFlag) {
        //添加二级科室校验二级科室的科室大类必须是一个一级科室
        StringBuffer errClassNameList = new StringBuffer();
        if (checkNameClassFlag) {
            List<SectionImage> checkKsClassName = sectionImageDao.checkClassName();
            if (checkKsClassName != null && checkKsClassName.size() > 0) {
                for (SectionImage cs : checkKsClassName) {
                    if (errClassNameList.length() == 0) {
                        errClassNameList.append("以下二级科室的科室大类不在一级科室中:");
                    }
                    errClassNameList.append(cs.getSectionId() + "," + cs.getSectionClassId() + ";");
                }
            }
        }
        // 校验二级科室必须在同义词中
        List<SectionImage> checkSection = sectionImageDao.checkKsNameSynonymy();
        StringBuffer errImageList = new StringBuffer();
        if (checkSection != null && checkSection.size() > 0) {
            for (SectionImage cs : checkSection) {
                if (errImageList.length() == 0) {
                    errImageList.append("以下图片不在科室同义词的科室名称中:");
                }
                errImageList.append(cs.getSectionId() + ";");
            }
        }

        //校验国家对应科室是否在科室图片名称中
        List<SectionCode> checkCode = sectionCodeDao.checkSectionCodeAndImage();
        StringBuffer errCodeList = new StringBuffer();
        if (checkCode != null && checkCode.size() > 0) {
            for (SectionCode sc : checkCode) {
                if (errCodeList.length() == 0) {
                    errCodeList.append("以下国家标准对应科室不在科室图片的科室名称中:");
                }
                errCodeList.append(sc.getSectionId() + ";");
            }
        }

        //校验黑名单是否在科室图片的科室名称中
        List<String> checkBlack = sectionBlackDao.checkBlackImageSection();
        StringBuffer errBlackList = new StringBuffer();
        if (checkBlack != null && checkBlack.size() > 0) {
            for (String sc : checkBlack) {
                if (errBlackList.length() == 0) {
                    errBlackList.append("以下黑名单科室不在科室图片的科室名称中:");
                }
                errBlackList.append(sc + ";");
            }
        }
        //校验医院对应科室是否在科室图片名称中
        List<String> checkHospital = sectionHospitalDao.checkHospitalImage();
        StringBuffer errHospitalList = new StringBuffer();
        if (checkHospital != null && checkHospital.size() > 0) {
            for (String sc : checkHospital) {
                if (errHospitalList.length() == 0) {
                    errHospitalList.append("以下医院科室对应科室不在科室图片的科室名称中");
                }
                errHospitalList.append(sc + ";");
            }
        }
        if (errImageList.length() > 0 || errCodeList.length() > 0 || errClassNameList.length() > 0 || errBlackList.length() > 0 || errHospitalList.length() > 0) {
            throw new RuntimeException(errImageList.toString() + "\n" + errCodeList.toString() + "\n" + errClassNameList.toString() + "\n" + errBlackList.toString() + "\n" + errHospitalList.toString());
        }
    }

    /**
     * 服务器文件重命名
     *
     * @param path
     * @param oldname
     * @param newname
     */
    private void renameFile(String path, String oldname, String newname) {
        if (!oldname.equals(newname)) {// 新的文件名和以前文件名不同时,才有必要进行重命名
            File oldfile = new File(path + "/" + oldname);
            File newfile = new File(path + "/" + newname);
            if (!oldfile.exists()) {
                // 重命名文件不存在
                LOGGER.info("文件不存在");
                return;
            }
            if (newfile.exists())// 若在该目录下已经有一个文件和新文件名相同，则不允许重命名
                LOGGER.info(newname + "已经存在！");
            else {
                oldfile.renameTo(newfile);
            }
        } else {
            LOGGER.info("新文件名和旧文件名相同");
        }
    }

    /**
     * 批量导入图片
     *
     * @param user
     * @param zipFile
     * @return
     * @throws IOException
     */
    @SuppressWarnings("resource")
    public ReturnData insertBatch(User user, MultipartFile zipFile) throws IOException {
        File file = File.createTempFile("tempZip", ".zip");
        zipFile.transferTo(file);
        ZipFile zf = new ZipFile(file);
        ZipEntry ze = null;
        String fileName = null;
        Enumeration<ZipEntry> em = zf.getEntries();
        List<String> imageNames = new ArrayList<>();

        Map<String, InputStream> imageInput = new HashMap<>();
        InputStream textIn = null;
        List<SectionImage> insertList = new ArrayList<>();
        while (em.hasMoreElements()) {
            ze = em.nextElement();
            // 如果当前条目是目录，报错
            if (ze.isDirectory()) {
                zf.close();
                return ReturnUtil.fail(ReturnCode.IMPORT_ZIP_DIRECTORY_ERROR);
            }
            fileName = ze.getName();
            if (fileName.endsWith(".png") || fileName.endsWith(".PNG")) {
                imageInput.put(fileName, zf.getInputStream(ze));
            } else if (fileName.endsWith(".txt") || fileName.endsWith(".TXT")) {
                textIn = zf.getInputStream(ze);
            }
        }
        //解析文件
        if (textIn != null) {
            ReturnData rtn = readMapperAndCreatClass(imageNames, textIn, user, insertList);
            if (rtn != null) {
                return rtn;
            }
        }
        //校验是否有图片名称对应没有图片
        for (String imageName : imageNames) {
            if (imageInput.get(imageName) == null) {
                //如果失败,删除有可能添加的section的记录
                sectionDao.deleteSectionInvalid();
                ReturnCode rc = ReturnCode.DYNAMIC_DESC_EXCEPTION;
                rc.setDesc("该图片名称没有对应图片:" + imageName);
                return ReturnUtil.fail(rc);
            }
        }
        //插入数据库
        //删除所有记录
        sectionImageDao.deleteAll();
        for (SectionImage si : insertList) {
            sectionImageDao.insert(si);
        }
        //校验科室图片或科室大类是否都在同义词的标准词中
        //校验国家对应科室是否在科室图片名称中 //批量导入时需要校验科室大类
        checkData(true);
        //分开上传
        for (String imageName : imageNames) {
            if (imageInput.get(imageName) != null) {
                decompressionPng(imageInput.get(imageName), imageName, uploadImagePath);
            }
        }
        //解析图片
        zf.close();
        return ReturnUtil.success();
    }

    /**
     * 解压出PNG图片
     *
     * @param in
     * @param fileName
     * @param decompressionPath
     * @throws IOException
     */
    private void decompressionPng(InputStream in, String fileName, String decompressionPath) throws IOException {
        byte[] buf = new byte[1024];
        int len = 0;
        OutputStream ot = null;
        try {
            ot = new FileOutputStream(decompressionPath + fileName);
            while ((len = in.read(buf)) != -1) {
                ot.write(buf, 0, len);
            }
        } catch (Exception e) {
            throw e;
        } finally {
            if (ot != null) {
                ot.flush();
                ot.close();
            }
            if (in != null) {
                in.close();
            }
        }
    }

    private ReturnData readMapperAndCreatClass(List<String> imageNames, InputStream in, User user, List<SectionImage> insertList) throws NumberFormatException, IOException {
        InputStreamReader read = new InputStreamReader(in, "UTF-8"); // 考虑到文本编码
        BufferedReader bf = new BufferedReader(read);
        String line = null;
        String s[] = null;
        List<String> checkRank = new ArrayList<>();
        List<Section> sts = sectionDao.retrieveList();
        Map<String, Long> ksNameAndSectionId = new HashMap<>();
        //获取所有已经存在的科室名称对应编号
        for (Section st : sts) {
            ksNameAndSectionId.put(st.getName(), st.getId());
        }
        while ((line = bf.readLine()) != null) {
            s = line.split("\t");
            String name = "";
            String departmentClass = "";
            String imageName = "";
            String rank = "";

            for (int i = 0; i < s.length; i++) {
                if (i == 0) name = s[i];
                if (i == 1) departmentClass = s[i];
                if (i == 2) imageName = s[i];
                if (i == 3) rank = s[i];
            }
            if (StringUtils.isNotBlank(imageName)) {
                if (!imageNames.contains(imageName)) {
                    imageNames.add(imageName);
                }
            }
            SectionImage di = new SectionImage();
            //校验rank
            if (StringUtils.isNotBlank(rank)) {
                if (checkRank.contains(departmentClass + "_" + rank)) {
                    ReturnCode rc = ReturnCode.DYNAMIC_DESC_EXCEPTION;
                    rc.setDesc("该排序在该科室大类下已经存在:" + departmentClass + "," + rank);
                    return ReturnUtil.fail(rc);
                } else {
                    checkRank.add(departmentClass + "_" + rank);
                }
                di.setRank(Integer.parseInt(rank));
            } else {
                ReturnCode rc = ReturnCode.DYNAMIC_DESC_EXCEPTION;
                rc.setDesc("该记录没有rank：" + name + "," + departmentClass + "," + rank);
                return ReturnUtil.fail(rc);
            }
            //科室名称和科室大类
            if (StringUtils.isBlank(name)) {
                di.setSectionId("0");
            } else if (ksNameAndSectionId.get(name) != null) {
                di.setSectionId(ksNameAndSectionId.get(name) + "");
            } else {
                //不存在需要新增
                Section value = new Section();
                value.setCnt(1);
                value.setDisable("0");
                value.setModifierId(user.getUserId());
                value.setName(name);
                value.setSexAgeFlag(0);
                value.setSex(0);
                value.setAge("");
                Long sectionId = sectionDao.insert(value);
                ksNameAndSectionId.put(name, sectionId);
                di.setSectionId(sectionId + "");
            }
            if (StringUtils.isBlank(departmentClass)) {
                di.setSectionClassId("0");
            } else if (ksNameAndSectionId.get(departmentClass) != null) {
                di.setSectionClassId(ksNameAndSectionId.get(departmentClass) + "");
            } else {
                //不存在需要新增
                Section value = new Section();
                value.setCnt(1);
                value.setDisable("0");
                value.setModifierId(user.getUserId());
                value.setName(departmentClass);
                value.setSexAgeFlag(0);
                value.setSex(0);
                value.setAge("");
                Long sectionId = sectionDao.insert(value);
                ksNameAndSectionId.put(departmentClass, sectionId);
                di.setSectionClassId(sectionId + "");
            }
            di.setImageName(imageName);

            if (StringUtils.isNotBlank(imageName)) {
                di.setImageUrl(FICTITIOUS_IMAGE_PATH + imageName);
            } else {
                di.setImageUrl("");
            }
            di.setModifierId(user.getUserId() + "");
            insertList.add(di);
        }
        return null;
    }

    /**
     * @param nameClass
     * @return
     * @throws IllegalStateException
     * @throws IOException
     */
    public ReturnData initSectionImageRank(String nameClass)
            throws IllegalStateException {
        int count = sectionImageDao.retrieveSizeByNameClass(nameClass);
        return ReturnUtil.success((count + 1) + "");
    }


    /**
     * 移动科室图片的位置，调整其排序
     *
     * @param user
     * @param id
     * @param flag 移动标识:0-上移，1-下移
     * @return
     */
    public ReturnData move(User user, String id, int flag) {
        SectionImage si = sectionImageDao.retrieveObjectById(Long.parseLong(id));
        SectionImage temp = null;
        if (flag == 1) {
            temp = sectionImageDao.selectFirstHighByRank(si.getRank(), si.getSectionClassId());
            if (temp == null) {
                return ReturnUtil.fail(ReturnCode.TESTING_CLASS_MOVE_HIGHEST_ERROR);
            }
        } else {
            temp = sectionImageDao.selectFirstLowByRank(si.getRank(), si.getSectionClassId());
            if (temp == null) {
                return ReturnUtil.fail(ReturnCode.TESTING_CLASS_MOVE_LOWEST_ERROR);
            }
        }
        int tempRank = temp.getRank();
        temp.setRank(si.getRank());
        temp.setModifierId(user.getUserId() + "");
        sectionImageDao.update(temp);
        si.setRank(tempRank);
        si.setModifierId(user.getUserId() + "");
        sectionImageDao.update(si);
        return ReturnUtil.success();
    }
//	// 删除目录下所有文件
//	public static boolean delAllFile(String path) {
//		boolean flag = false;
//		File file = new File(path);
//		if (!file.exists()) {
//			return flag;
//		}
//		if (!file.isDirectory()) {
//			return flag;
//		}
//		String[] tempList = file.list();
//		File temp = null;
//		for (int i = 0; i < tempList.length; i++) {
//			if (path.endsWith(File.separator)) {
//				temp = new File(path + tempList[i]);
//			} else {
//				temp = new File(path + File.separator + tempList[i]);
//			}
//			if (temp.isFile()) {
//				temp.delete();
//			}
//		}
//		return flag;
//	}
}
